package com.chookss.tiku

import androidx.lifecycle.MutableLiveData
import com.chookss.tiku.entity.LeftEntiry
import com.johnrambo.ktea.base.BaseViewModel
import com.johnrambo.ktea.net.http.Method
import com.johnrambo.ktea.net.http.httpBaseList

class SelectPracticeModel : BaseViewModel() {

    val leftLiveData by lazy { MutableLiveData<List<LeftEntiry>>() }
    val rightLiveData by lazy { MutableLiveData<List<LeftEntiry>>() }
    val rightCyLiveData by lazy { MutableLiveData<List<LeftEntiry>>() }
    val errorLiveData by lazy { MutableLiveData<String>() }

    fun getLeft(
        catalogType: String,
        timestamp: String,
        nonce: String,
        sign: String
    ) {
        jobs + httpBaseList<LeftEntiry> {
            url = "api/subject/getCatalog"
            method = Method.POST
            params = mutableMapOf(
                "catalogType" to catalogType,
                "timestamp" to timestamp,
                "nonce" to nonce,
                "sign" to sign
            )
            onSuccess = { leftLiveData.value = it }
            onError = { errorLiveData.value = it }
        }
    }

    fun getRight(
        catalogType: String,
        parentCode:String,
        timestamp: String,
        nonce: String,
        sign: String
    ) {
        jobs + httpBaseList<LeftEntiry> {
            url = "api/subject/getCatalog"
            method = Method.POST
            params = mutableMapOf(
                "catalogType" to catalogType,
                "parentCode" to parentCode,
                "timestamp" to timestamp,
                "nonce" to nonce,
                "sign" to sign
            )
            onSuccess = { rightLiveData.value = it }
            onError = { errorLiveData.value = it }
        }
    }

    fun getCyRight(
        timestamp: String,
        nonce: String,
        sign: String
    ) {
        jobs + httpBaseList<LeftEntiry> {
            url = "api/practice/getPracticeCommonCatalog"
            method = Method.POST
            params = mutableMapOf(
                "timestamp" to timestamp,
                "nonce" to nonce,
                "sign" to sign
            )
            onSuccess = { rightCyLiveData.value = it }
            onError = { errorLiveData.value = it }
        }
    }
}